import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import commonjs from 'vite-plugin-commonjs';
// https://vite.dev/config/
export default defineConfig({
  server: {
    host: '0.0.0.0',  // 允许局域网访问
    port: 8123,       // 指定端口
    proxy: {
      '/api': { 
        target: 'http://192.168.1.13:8124',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    commonjs(),
    ],
  optimizeDeps: {
    include: ['fabric']  // 确保 fabric 被处理
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
